import java.io.*;

/**
 * Copyright: Copyright (c) 2018 Ztesoft
 *
 * @ClassName: PACKAGE_NAME.Person
 * @Description: 该类的功能描述
 * @version: v1.0.0
 * @author: wangtongbang
 * @date: 2018/6/27 10:21
 * <p>
 * Modification History:
 * Date         Author          Version            Description
 * ------------------------------------------------------------
 * 2018/6/27      wangtongbang          v1.0.0               修改原因
 */
public class Person implements Externalizable {

    private String name;
    private int sex;
    private String address;

    public Person() {
    }

    public Person(String name, int sex, String address) {
        this.name = name;
        this.sex = sex;
        this.address = address;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getSex() {
        return sex;
    }

    public void setSex(int sex) {
        this.sex = sex;
    }


    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    /**
     * 序列化操作的扩展类
     *
     * @param out
     */
    public void writeExternal(ObjectOutput out) throws IOException {
        //这里可以进行属性的新增
        int age = 0;
        out.writeObject(name);
        out.writeObject(sex);
        out.writeObject(address);
        out.writeObject(age);
    }

    /**
     * 反序列化操作的扩展类
     *
     * @param in
     */
    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
        //注意这里的接受顺序是有限制的哦，否则的话会出错的
        // 例如上面先write的是A对象的话，那么下面先接受的也一定是A对象...
        name = (String) in.readObject();
        sex = (Integer) in.readObject();
        address = (String) in.readObject();
        int age = (Integer) in.readObject();
        System.out.println("我们在序列化过程中新增的age属性值为：" + age);
    }

    @Override
    public String toString() {
        return "Person{" + "name='" + name + '\'' + ", sex=" + sex + ",address='" + address + '\'' + '}';
    }
}
